with Rational_Numbers.Binary_Operators;
with Rational_Numbers.Reduce;
package body Rational_Numbers.Binary_Operators is

   function "+" (X, Y : Rational) return Rational is
      Res : Rational;
   begin
      Res.Denominator := X.Denominator * Y.Denominator;
      Res.Numerator := X.Numerator * Y.Denominator + Y.Numerator * X.Denominator;

      -- reduce
      Res := Reduce(Res);
     return Res;
   end "+";

   function "-" (X, Y : Rational) return Rational is
      Res : Rational;
   begin
      Res.Denominator := X.Denominator * Y.Denominator;
      Res.Numerator := X.Numerator * Y.Denominator - Y.Numerator * X.Denominator;

      -- reduce
      Res := Reduce(Res);
      return Res;
   end "-";

   function "*" (X, Y : Rational) return Rational is
      Res : Rational;
   begin
      Res.Numerator := X.Numerator * Y.Numerator;
      Res.Denominator := X.Denominator * Y.Denominator;
      --reduce
      Res := Reduce(Res);
      return Res;
   end "*";

   function "/" (X, Y : Rational) return Rational is
      Res : Rational;
      Y2 : Rational := Integer(Y.Denominator)/Y.Numerator;
   begin
      Res := X*Y2;
      Res := Reduce(Res);
      return Res;
   end "/";



end Rational_Numbers.Binary_Operators;
